<template>
  <div>
    <el-dialog
      :title="title"
      :visible.sync="visible"
      width="60%"
      append-to-body
      custom-class="import-dialog"
    >
      <div class="app-container">
        <el-form
          :model="queryParams"
          ref="queryForm"
          size="small"
          :inline="true"
        >
          <el-form-item label="房间号" prop="roomNumber">
            <el-input
              v-model="queryParams.roomNumber"
              placeholder="请输入房间号"
              clearable
              style="width: 240px"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              >搜索</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
              >重置</el-button
            >
          </el-form-item>
        </el-form>

        <el-table
          v-loading="loading"
          :data="list"
          @selection-change="handleSelectionChange"
          ref="table"
        >
          <el-table-column label="房间编号" align="center" prop="houseId" />
          <el-table-column label="房间号" align="center" prop="roomNumber" />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                @click="selectHosue(scope.row)"
                v-hasPermi="['contract:template:detail']"
                >选择房屋</el-button
              >
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total > 0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listRoom } from "@/api/house/room";
export default {
  props: {
    title: {
      default: "选择房间",
    },
    value: {
      default: false,
    },
  },
  dicts: ["dict_unsubscribe_rule_type"],
  data() {
    return {
      visible: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        roomNumber: undefined,
        apartmentType: undefined,
        editStatus: undefined,
        apartmentState: undefined,
        updateBy: undefined,
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 总条数
      total: 0,
      //列表
      list: [],
    };
  },
  watch: {
    value(newVal, oldVal) {
      if (newVal) {
        this.init();
      }
      this.visible = newVal; // 监测value的变化，并赋值。
    },
    visible(val) {
      this.$emit("input", val); // 此处监测visible目的为关闭弹窗时，重新更换value值，注意emit的事件一定要为input。
    },
  },
  methods: {
    init() {
      this.getList();
    },
    handleQuery() {
      this.getList();
    },
    resetQuery() {
      // this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /** 查询房间列表 */
    getList() {
      this.loading = true;
      listRoom(this.queryParams).then((response) => {
        this.list = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    handleSelectionChange() {},
    selectHosue(item) {
      this.$emit("success", item);
      this.close()
    },
    close() {
      this.resetQuery();
      this.visible = false;
    },
  },
};
</script>

<style lang="scss" scoped>
</style>